"""
Author: runyu.ma

eval_pystr_pass.py
"""

from typing import Dict
from ..core.dslc_parser import String, Identifier, BinaryOp, Number
from ..core.dslc_symbol_table import SymbolTable


def const_def_in_tab(stab: SymbolTable, top: BinaryOp):
    if not isinstance(top, BinaryOp):
        raise ValueError("not BinaryOp Node")
    #
    if top.op == '=' and isinstance(top.l, Identifier):
        if isinstance(top.r, String) or isinstance(top.r, Number):
            stab.add(top.l.name, {'ival': top.r.value})
    return top

